home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 34.zip / BS1 part 34 / FredFish PD 314.adf / Zc / zcsrc.lzh / IOLib / stdio / fputc.c < prev    next >
C/C++ Source or Header  |  1989-05-20  |  655b  |  31 lines

  1. #include <stdio.h>
  2.  
  3. int fputc(c, fp)
  4.     register unsigned char c;
  5.     register FILE *fp;
  6.     {
  7.     register int f, m, mustflush, rv;
  8.  
  9.     f = (fp->_flag |= _IORW);
  10.     if(!(f & _IOWRT)            /* not opened for write? */
  11.     || (f & (_IOERR | _IOEOF)))        /* error/eof conditions? */
  12.         return(EOF);
  13.     if(fp->_base == NULL)    /* allocate a buffer if there wasn't one */
  14.         _getbuf(fp);
  15. _fputc:
  16.     *(fp->_ptr)++ = c;
  17.     mustflush = (fp->_flag & _IODEV) && (c == '\n');
  18.     if((++(fp->_cnt)) >= fp->_bsiz || mustflush)
  19.         {
  20.         fp->_ptr = fp->_base;
  21.         m = fp->_cnt;
  22.         if((rv = write(fp->_file, fp->_base, m)) != m)
  23.             {
  24.             fp->_flag |= _IOERR;
  25.             return(EOF);
  26.             }
  27.         fp->_cnt = 0;
  28.         }
  29.     return(c);
  30.     }
  31.